# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Michael Koloberdin <koloberdin@gmail.com>
# Contributor: tochiro@no.spam.mail.berlios.de
# Contributor: Andreas W. Hauser <andy-aur@splashground.de>
# Contributor: Brian De Wolf <arch@bldewolf.com>

pkgname=mlton
pkgver=20210117
pkgrel=5
pkgdesc='Whole-program, optimizing Standard ML compiler'
arch=(loong64 x86_64)
# no HTTPS available
url='http://mlton.org/'
license=(BSD LGPL MIT)
depends=(gmp)
makedepends=(git mlton setconf)
options=(staticlibs)
source=("git+https://github.com/MLton/mlton#commit=b1f1f0f0916d28c0d183fba85549d5bf96f1fa41") # tag: on-20210117-release
b2sums=(SKIP)

prepare() {
  cd $pkgname
  make MLTON_VERSION="$pkgver" version
}

build() {
  make -C $pkgname MLTON_COMPILE_ARGS="-link-opt -Wl,-z,relro,-z,now"
}

check() {
  echo 'print("42");' > simple.sml
  $pkgname/build/bin/mlton simple.sml && test $(./simple) -eq 42
}

package() {
  make -C $pkgname PREFIX=/usr DESTDIR="$pkgdir" install
  for f in $pkgname/doc/license/*-LICENSE; do
    install -Dm644 "$f" "$pkgdir/usr/share/licenses/$pkgname/$f"
  done
}
